<!--
  ~ Copyright (c) 2020 the original author or authors
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      https://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  ~ or implied. See the License for the specific language governing
  ~ permissions and limitations under the License.
  -->
<mat-card class="sign-up-card">
  <div class="form-card--logo">
    <img src="assets/img/face-recognition-logo.svg" class="logo-img" alt="log-in-logo" />
  </div>
  <mat-card-header class="form-card--title">
    <mat-card-title>{{ 'registration.title' | translate }}</mat-card-title>
  </mat-card-header>
  <mat-card-content>
    <form class="form-card--form" [formGroup]="form" (ngSubmit)="onSubmit()" id="signUpForm">
      <div class="mat-input-wrapper">
        <mat-form-field appearance="outline" hideRequiredMarker>
          <mat-label>{{ 'registration.first_name' | translate }}</mat-label>
          <mat-error>
            <span>{{ 'registration.name_restriction' | translate }}</span>
          </mat-error>
          <input matInput formControlName="firstName" name="firstName" required />
        </mat-form-field>
        <mat-form-field appearance="outline" hideRequiredMarker>
          <mat-label>{{ 'registration.last_name' | translate }}</mat-label>
          <mat-error>
            <span>{{ 'registration.last_name_restriction' | translate }}</span>
          </mat-error>
          <input matInput formControlName="lastName" name="lastName" required />
        </mat-form-field>
      </div>
      <mat-form-field appearance="outline" hideRequiredMarker>
        <mat-label>{{ 'registration.email' | translate }}</mat-label>
        <mat-error>
          <span>{{ 'registration.email_hint' | translate }}</span>
        </mat-error>
        <input matInput formControlName="email" name="email" type="email" required />
      </mat-form-field>
      <mat-form-field appearance="outline" hideRequiredMarker>
        <mat-label>{{ 'registration.password' | translate }}</mat-label>
        <mat-hint>{{ 'registration.password_restriction' | translate }}</mat-hint>
        <mat-error>
          <span>{{ 'registration.password_restriction' | translate }}</span>
        </mat-error>
        <input matInput formControlName="password" type="password" name="password" required />
      </mat-form-field>
      <mat-form-field appearance="outline" hideRequiredMarker>
        <mat-label>{{ 'registration.confirm_password' | translate }}</mat-label>
        <mat-hint>{{ 'registration.password_restriction' | translate }}</mat-hint>
        <mat-error>
          <span>{{ 'registration.password_restriction' | translate }}</span>
        </mat-error>
        <input matInput formControlName="confirmPassword" type="password" name="confirmPassword" required />
      </mat-form-field>
      <mat-checkbox formControlName="isAllowStatistics" class="sign-up-full-width" *ngIf="isDemoPageAvailable$ | async">
        <span class="white-space-fix"
          >{{ 'registration.statistics' | translate }}
          <a href="https://github.com/exadel-inc/CompreFace/blob/master/docs/Gathering-anonymous-statistics.md">{{
            'registration.more_info' | translate
          }}</a></span
        >
      </mat-checkbox>

      <mat-error *ngIf="form.errors?.passwordMismatch && !form.get('confirmPassword').errors?.minlength">
        <span>{{ 'registration.password_dont_match' | translate }}</span>
      </mat-error>
    </form>
  </mat-card-content>
  <mat-card-actions class="form-card--btn-wrapper">
    <button class="btn" mat-flat-button type="submit" form="signUpForm" color="primary" [disabled]="form.invalid || (isLoading$ | async)">
      {{ 'registration.sign_up' | translate }}
    </button>
    <div class="link">
      <span
        >{{ 'registration.have_account' | translate }}
        <a color="primary" [routerLink]="[routes.Login]">{{ 'registration.login' | translate }}</a>
      </span>
    </div>
  </mat-card-actions>
</mat-card>
